package com.cooper.servlet;

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cooper.service.admin.DisplayPicConfigService;
import com.cooper.service.admin.MallCategoryService;
import com.cooper.vo.MallCategoryVo;

@Component("contextStartupServlet")
public class ContextStartupServlet extends HttpServlet {

	private static final long serialVersionUID = -2852768272213602745L;
	
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private MallCategoryService mallCategoryService;
	
	@Autowired
	private DisplayPicConfigService displayPicConfigService;
	
	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		List<MallCategoryVo> firstLevelCategoryList = this.mallCategoryService.getAllCategoryWithChilds();
		if(firstLevelCategoryList!=null&&!firstLevelCategoryList.isEmpty()){
			for(MallCategoryVo vo:firstLevelCategoryList){
//				if(vo.getParentId()==1){//一级类目取三张上传的图片
//					DisplayPicConfigVo queryParamVo = new DisplayPicConfigVo();
//					queryParamVo.setStatus(DisplayPicConfigListDo.DISPLAY_YES);
//					queryParamVo.setDisType("mallcategory"+vo.getId());
//					PageInfo pageInfo = new pageInfo();
//					pageInfo.setCurPage(1);
//					pageInfo.setPageSize(3);
//					PageResult<DisplayPicConfigVo> ret = this.displayPicConfigService.queryDisplayPicConfigPage(queryParamVo, pageInfo);
//					if(ret!=null&&ret.getDataList()!=null){
//						vo.setDisplayPicConfigList(ret.getDataList());
//					}
//				}
			}
		}
		
		this.getServletContext().setAttribute("firstLevelCategoryList", firstLevelCategoryList);
	}
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}
}
